package org.example.security.config;

import org.example.security.interceptor.BackendInterceptor;
import org.example.security.interceptor.FrontInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 小杰_cc
 * @version 1.0
 */

@Configuration
public class MyWebConfig implements WebMvcConfigurer {


    public static final String[] backend_excludeUrls = {
            "/sys/backend/login","/sys/backend/logout","/sys/backend/captchaImg","/*/front/**","/auth/**","/message/**",
    };

    public static final String[] front_excludeUrls = {
            "/*/backend/**","/auth/**","/message/**", "/oms/front/alipay/pay", "/oms/front/alipay/notify"
    };

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 后台端拦截器
        registry.addInterceptor(new BackendInterceptor())
                .excludePathPatterns(backend_excludeUrls)
                .addPathPatterns("/*/backend/**")
                .order(1);

        // 前台端拦截器
        registry.addInterceptor(new FrontInterceptor())
                .excludePathPatterns(front_excludeUrls)
                .addPathPatterns("/*/front/**")
                .order(2);
    }

}